package cn.yj.core.business.controller;

import cn.yj.annotation.pagehelper.page.OrderBy;
import cn.yj.annotation.pagehelper.page.PageUtils;
import cn.yj.cgs.dba.entity.vo.CustomerPcVo;
import cn.yj.admin.frame.AbstractController;
import cn.yj.syslog.common.LogType;
import cn.yj.syslog.common.OperateLog;
import cn.yj.core.business.service.CustomerService;
import cn.yj.entity.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 永健
 * @since 2021-06-09 15:16
 */
@RequestMapping("/customer")
@RestController
public class CustomerController extends AbstractController<CustomerPcVo> {

    @Resource
    private CustomerService customerService;

    @Override
    @GetMapping("/pageList")
    @RequiresPermissions("customer:list")
    public R pageList(@RequestParam Map<String, Object> params) {
        return success(customerService.pageList(params, page()));
    }

    @GetMapping("/newUsers")
    public R pageList() {
        return success(customerService.pageList(new HashMap<>(), page(new OrderBy(OrderBy.Direction.DESC,"create_time"))));
    }

    @PutMapping("/changeUserStatus")
    @RequiresPermissions("customer:changeUserStatus")
    @OperateLog(describe = "更改用户状态",type = LogType.UPDATE)
    public R changeUserStatus(@RequestBody Map<String, Object> params) {
        return success(customerService.changeUserStatus(params));
    }

    @GetMapping("/rankingList")
    @RequiresPermissions("customer:rankingList")
    public R rankingList(@RequestParam Map<String, Object> params) {
        params.put("userCode",null);
        return success(customerService.inviteesRankingList(params, PageUtils.page()));
    }
}
